package com.wuad.platformwuad.module.study.stringMethods;

import cn.hutool.core.date.DateUtil;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 字符串替换
 *
 * @author wuad
 */
public class ReplaceMethodDemo {

    public static void main(String[] args) {

        // 短信模板替换
        String str = smsReplace();
        System.out.println(str);

        dateReplace();

    }

    /**
     * 短信模板替换
     *
     * @return
     */
    public static String smsReplace() {
        Map<String, String> map = new HashMap<>();
        map.put("$CstMgr$","111");
        map.put("$OrgNM$","222");
        map.put("$Title$","333");
        map.put("$CstNM$","4444");
        map.put("$EndDt$","555");
        map.put("$BegDt$","6666");
        map.put("$PrdNM$","7777");
        map.put("$Date$","8888");

        String ss = "尊敬的$CstNM$$Title$，祝您生日快乐，我是$OrgNM$的$CstMgr$";

        for (int i = 0; i < map.size(); i++) {
            Set<String> keySet = map.keySet();
            for(String key : keySet){
                ss = ss.replace(key, map.get(key));
            }
        }
        return ss;
    }

    public static void dateReplace() {
        String newDate = DateUtil.format(new Date(),"yyyy-M-d");
        System.out.println("获取当日日期：" + newDate);
        String[] ss = newDate.split("-");
        for(String s : ss) {
            System.out.println("1212:" + s);
        }
    }

    /**
     * replace 字符替换
     */
    public static class replace {
        public static void main(String[] args) {
            // 字符替换时转义符的使用
//            String sss = "(la_a00056_r='V4')";
//            System.out.println("111111" + sss.replaceAll("\\\\'","'"));
//            System.out.println("222222" + sss.replaceAll("'","\\\\'"));

            String s1 = "[2024/12/17/12.ceshi.xlsx:XLSX]";

            System.out.println(s1.substring(1, s1.lastIndexOf("]" +
                    "")));
        }
    }

}